
interface fileInfo {
    path: String,
    name: String,
    component: any
}
const autoRoute: Array<any> = []

//获取vue文件
export const files = require.context('@/views', true, /[A-Za-z0-9-_,\s]+\.vue$/i)
files.keys().forEach((item: any) => {
    autoRoute.push(getFileInfo(item))

})
// 获取文件信息
function getFileInfo(key: string) {
    const path = key.replace(/(\.\/)|(\.\w+$)/g, '').split("/");
    let routerInfo: fileInfo = {
        path: `/${path.join('/').toLowerCase()}`,
        name: path[path.length - 1],
        component: () => import(`../views/${path.join('/')}.vue`)
    }
    return routerInfo
}
export default autoRoute
